package com.ywgt.controller;

import com.ywgt.pojo.StatVo;
import com.ywgt.service.StatService;
import com.ywgt.util.ResponseUtil;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/admin/stat")
@ApiModel("统计管理")
public class StatController {

    @Autowired
    StatService statService;
    @GetMapping("/user")
    public Object getUsers(){
        List<Map> rows = statService.statUser();
        String[] columns = new String[] { "day", "users" };
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return ResponseUtil.ok(statVo);
    }

    @GetMapping("/goods")
    public Object getGoods(){
        List<Map> rows = statService.statGoods();
        String[] columns = new String[] { "day", "orders", "products", "amount" };
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return ResponseUtil.ok(statVo);
    }

    @GetMapping("/order")
    public Object getOrders(){
        List<Map> rows = statService.statOrder();
        String[] columns = new String[] { "day", "orders", "customers", "amount", "pcr" };
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return ResponseUtil.ok(statVo);
    }
}
